import type { IFormItem } from '@/components/NFormBuilder/types'
import type { CreateFormItemsOptions } from '@/types/fcform'
import { ScConstants } from '@/components/NFormBuilder/unit/ScConstants'

export const createFormItems = (options: CreateFormItemsOptions): IFormItem[] => {
  const { formData } = options
  const showType = computed(() => {
    const publicKey = (formData.value.publicKey as string) || ''
    if (publicKey.includes('NUMBER')) {
      return 'number'
    }
    if (publicKey.includes('RICH')) {
      return 'rich'
    }
    if (publicKey.includes('IMAGE')) {
      return 'image'
    }
    if (publicKey.includes('FILE')) {
      return 'file'
    }
    return 'input'
  })
  const sc = new ScConstants(24)
  return [
    sc.input('标签名', 'publicName'),
    sc.input('标识', 'publicKey'),
    {
      ...sc.number('数值', 'publicValue'),
      hidden: () => showType.value !== 'number',
    },
    {
      ...sc.rich('内容', 'publicValue'),
      hidden: () => showType.value !== 'rich',
    },
    {
      ...sc.image('图片', 'publicValue'),
      hidden: () => showType.value !== 'image',
    },
    {
      ...sc.file('模板', 'publicValue'),
      hidden: () => showType.value !== 'file',
    },
    {
      ...sc.input('内容', 'publicValue'),
      hidden: () => showType.value !== 'input',
    },
  ]
}
